<style type="text/css">
	a.btnDelete img{display:none}
</style>

<div class="box_type02">
	<h2 class="txt">컨텐츠관리</h2>
	<p class="icon"><a href="javascript:void(0);" class="icon_m04">매뉴얼</a></p>

	<div class="contCont">
		<ul class="c_box">
			<li class="left">
				<div id="contsMenu">
					<div class="addPlus">
						<input type="text" id="" name="" class="ip" value="상위메뉴추가" />
						<input type="submit" class="btn_search" title="검색" value="" />
					</div>
					<div id="demo" class="demo" style="background:#ffffff"></div>
				</div>
			</li>
			<li class="right">
			<!--[s] 쓰기 -->
			<form name="frmReg" method="post" action="/contents/contentsForm/contents_html">
			<input type="hidden" name="id" value="<?=$id?>">
			<input type="hidden" name="dbjob" value="<?php echo $dbjob?>">
			<input type="hidden" name="auth_write" value="<?php echo $auth_write?>">
			<input type="hidden" name="auth_comment" value="<?php echo $auth_comment?>">
			<input type="hidden" name="auth_view" value="<?php echo $auth_view?>">
				<fieldset class="board_write">
					<legend>컨텐츠관리</legend>
					<table cellspacing="0" summary="컨텐츠관리">
						<caption>컨텐츠관리</caption>
						<tr>
							<th scope="row" width="100"><p class="point">기능선택</p></th>
							<td>
								<div>
									<ul class="w20 c_box">
										<?php
										foreach($this->config->item('ch_contents') as $key => $value){
											$checked = ($key == 'GALLERY') ? 'checked' : '';
											echo "<li><input type=\"radio\" id=\"types{$key}\" name=\"page_type\" class=\"ip_c\" value=\"{$key}\" {$checked} /><label for=\"types{$key}\" class=\"txt_type01\">{$value}</label></li>\n";
										}
									?>
									</ul>
								</div>
							</td>
						</tr>
						<tr>
							<th scope="row"><p class="point">제목</p></th>
							<td>
								<div><input type="text" id="" name="title" class="ip_i" style="width:481px;" value="<?php echo $title?>" /></div>
							</td>
						</tr>
						<tr>
							<th scope="row"><p class="point">키워드</p></th>
							<td>
								<div><input type="text" id="" name="keyword" class="ip_i" style="width:481px;" value="<?php echo $keyword?>" /></div>
							</td>
						</tr>
						<tr>
							<th scope="row"><p class="point">설명</p></th>
							<td>
								<div><input type="text" id="" name="description" class="ip_i" style="width:481px;" value="<?php echo $description?>" /></div>
							</td>
						</tr>
						<tr>
							<th scope="row"><p>스킨</p></th>
							<td>
								<div>
									<select name="gallery_skin" class="ip_s" style="width:300px;">
										<?php
											$dic = directory_map('./gallery/skin',1);
											foreach($dic as $item){
												$selected = ($item == $board_skin) ? 'selected' : null;
												echo "<option value=\"$item\" {$selected}>$item</option>\n";
											}
											/*foreach($this->config->item('ch_skin') as $key => $value){
												echo "<option value=\"$value\">$value</option>\n";
											}*/
										?>
									</select>
								</div>
							</td>
						</tr>
						<tr>
							<th scope="row"><p>말줄임표시</p></th>
							<td>
								<div>
									<input type="text" id="" name="limit_title" class="ip_i" style="width:80px;" value="<?php echo $limit_title?>" />
									<span class="txt_type03">자 이상 말줄임(게시물목록)</span>
								</div>
							</td>
						</tr>
						<tr>
							<th scope="row"><p>목록갯수</p></th>
							<td>
								<div>
									<ul class="w40 c_box">
										<li>
											<input type="text" id="" name="cnt_row" class="ip_i" style="width:80px;" value="<?php echo $cnt_row?>" />
											<strong class="txt_type03">행</strong>
										</li>
										<li>
											<input type="text" id="" name="cnt_col" class="ip_i" style="width:80px;" value="<?php echo $cnt_col?>" />
											<strong class="txt_type03">열</strong>
										</li>
									</ul>
								</div>
							</td>
						</tr>
						<tr>
							<th scope="row"><p>썸네일</p></th>
							<td>
								<div>
									<ul class="w40 c_box">
										<li>
											<input type="text" id="" name="thumbnail_width" class="ip_i" style="width:80px;" value="<?php echo $thumbnail_width?>" />
											<strong class="txt_type03">Width</strong>
										</li>
										<li>
											<input type="text" id="" name="thumbnail_height" class="ip_i" style="width:80px;" value="<?php echo $thumbnail_height?>" />
											<strong class="txt_type03">height</strong>
										</li>
									</ul>
								</div>
							</td>
						</tr>
						<tr>
							<th scope="row"><p>쓰기</p></th>
							<td>
								<div>
									<ul class="w20 c_box">
										<li><input type="checkbox" id="typess" name="all_write" class="ip_c" /><label for="typess" class="txt_type01">전체</label></li>
										<li><input type="checkbox" id="typess2" name="check_write" class="ip_c" /><label for="typess2" class="txt_type01">관리자</label></li>
										<li><input type="checkbox" id="typess3" name="check_write" class="ip_c" /><label for="typess3" class="txt_type01">회원</label></li>
										<li><input type="checkbox" id="typess4" name="check_write" class="ip_c" /><label for="typess4" class="txt_type01">비회원</label></li>
									</ul>
								</div>
							</td>
						</tr>
						<!-- <tr>
							<th scope="row"><p>답변</p></th>
							<td>
								<div>
									<ul class="w20 c_box">
										<li><input type="checkbox" id="typess" name="2" class="ip_c" /><label for="typess" class="txt_type01">전체</label></li>
										<li><input type="checkbox" id="typess2" name="2" class="ip_c" /><label for="typess2" class="txt_type01">관리자</label></li>
										<li><input type="checkbox" id="typess3" name="2" class="ip_c" /><label for="typess3" class="txt_type01">회원</label></li>
										<li><input type="checkbox" id="typess4" name="2" class="ip_c" /><label for="typess4" class="txt_type01">비회원</label></li>
									</ul>
								</div>
							</td>
						</tr> -->
						<tr>
							<th scope="row"><p>댓글</p></th>
							<td>
								<div>
									<ul class="w20 c_box">
										<li><input type="checkbox" id="typess" name="all_comment" class="ip_c" /><label for="typess" class="txt_type01">전체</label></li>
										<li><input type="checkbox" id="typess2" name="check_comment" class="ip_c" /><label for="typess2" class="txt_type01">관리자</label></li>
										<li><input type="checkbox" id="typess3" name="check_comment" class="ip_c" /><label for="typess3" class="txt_type01">회원</label></li>
										<li><input type="checkbox" id="typess4" name="check_comment" class="ip_c" /><label for="typess4" class="txt_type01">비회원</label></li>
									</ul>
								</div>
							</td>
						</tr>
						<tr>
							<th scope="row"><p>읽기</p></th>
							<td>
								<div>
									<ul class="w20 c_box">
										<li><input type="checkbox" id="typess" name="all_view" class="ip_c" /><label for="typess" class="txt_type01">전체</label></li>
										<li><input type="checkbox" id="typess2" name="check_view" class="ip_c" /><label for="typess2" class="txt_type01">관리자</label></li>
										<li><input type="checkbox" id="typess3" name="check_view" class="ip_c" /><label for="typess3" class="txt_type01">회원</label></li>
										<li><input type="checkbox" id="typess4" name="check_view" class="ip_c" /><label for="typess4" class="txt_type01">비회원</label></li>
									</ul>
								</div>
							</td>
						</tr>
						<tr>
							<th scope="row"><p>비밀글</p></th>
							<td>
								<div>
									<a href="javascript:void(0);" class="disBtn"><img src="/theme/<?=$_theme?>/images/common/btn_on_off.gif" alt="on" /></a>
									<!-- 히든 인풋박스에 on off 들어가게 구성되어 있음 -->
									<input type="hidden" id="displays" name="secret_yn" value="<?php echo $secret_yn?>" />
								</div>
							</td>
						</tr>
					</table>
				</fieldset>
				<!--[e] 쓰기 -->
			</form>
			</li>
		</ul>
	</div>

	<!-- [s] 버튼 -->
	<ul class="botton_box mt30">
		<li class="center">
			<a href="javascript:frmValid();" class="btnAdd"><img src="/theme/<?=$_theme?>/images/common/btn_ok.gif" alt="확인" /></a>
			<!--<a href="javascript:void(0);"><img src="/theme/<?=$_theme?>/images/common/btn_modify.gif" alt="수정" /></a>  -->
			<a href="javascript:frmDelete();" class="btnDelete"><img src="/theme/<?=$_theme?>/images/common/btn_delete.gif" alt="삭제" /></a>
			<!--<a href="javascript:void(0);"><img src="/theme/<?=$_theme?>/images/common/btn_cancel.gif" alt="취소" /></a>  -->
		</li>
	</ul>
	<!-- [e] 버튼 -->

	<!--[s] Tip -->
	<dl id="tip" class="mt30">
		<dt>Tip</dt>
		<dd>인터넷익스플로러의 '호환성보기' 기능을 사용중인 접속자에게 자동으로 최신버전 기준으로 사이트를 출력하도록 처리합니다.</dd>
		<dd>코딩방식에 따라 특정 버전의 브라우저에서 사이트가 깨질수 있으니, 충분한 테스트 후 기능을 설정해 주시기 바랍니다.</dd>
	</dl>
	<!--[e] Tip -->
</div>
<script type="text/javascript">
<!--
function setMenu(){
	with(document.frmMenu){
		if(!menu_nm.value){
			alert("메뉴명을 입력해주세요");
			return;
		}
	}	

	$.ajax({
		type: "POST",
		url: "/chmanager/ajax_menu",
		data: $("[name=frmMenu]").serialize(),
		success: function(data){
			alert(data);
			
		},
		error:function(error){
			alert('에러');
		}
	});
}

function frmValid(){
	var str_write='';
	var str_reply='';
	var str_comment='';
	var str_view='';
	
	$("[name=check_write]").each(function(){ //쓰기
		str_write += ($(this).attr("checked")) ? "1" : "0";
	});

	$("[name=check_comment]").each(function(){ //댓글
		str_comment += ($(this).attr("checked")) ? "1" : "0";
	});

	$("[name=check_view]").each(function(){ //보기
		str_view += ($(this).attr("checked")) ? "1" : "0";
	});
		
	with(document.frmReg){
		$("[name=page_type]").attr("disabled",false);
		auth_write.value = str_write;
		auth_comment.value = str_comment;
		auth_view.value = str_view;
		submit();
	}
}

function frmDelete(){
	if(!confirm('삭제 하시겠습니까?'))return;
	with(document.frmReg){
		dbjob.value = 'd';
		submit();
	}	 
}

$(function () {
	var uri_template = {"HTML":"/chmanager/contents/contents_html","BOARD":"/chmanager/contents/contents_board","GALLERY":"/chmanager/contents/contents_gallery"};

	$("[name=page_type]").change(function(){
		var contents_template= uri_template[$(this).val()];
		location.href = contents_template+'/id/'+$("[name=id]").val();
	});
	
	if($("[name=dbjob]").val() == 'u'){ 
		$("[name=page_type]").attr("disabled",true);
		$("a.btnDelete img").show();

		//쓰기
		//alert($("[name=auth_write]").val().length)
		for(var i=0; i < $("[name=auth_write]").val().length; i++){
			if($("[name=auth_write]").val().substr(i,1) == 1){
				$("[name=check_write]").eq(i).attr("checked",true);
			}
		}
		
		//댓글
		for(var i=0; i < $("[name=auth_comment]").val().length; i++){
			if($("[name=auth_comment]").val().substr(i,1) == 1){
				$("[name=check_comment]").eq(i).attr("checked",true);
			}
		}
		//보기
		for(var i=0; i < $("[name=auth_view]").val().length; i++){
			if($("[name=auth_view]").val().substr(i,1) == 1){
				$("[name=check_view]").eq(i).attr("checked",true);
			}
		}
	}

	if($("[name=id]").val()) $(".btnAdd").show();

	//쓰기전체 선택
	$("[name=all_write]").click(function(){
		var bool = ($(this).attr("checked"))? true : false;
		$("[name=check_write]").attr("checked",bool);
	});

	//댓글전체 선택
	$("[name=all_comment]").click(function(){
		var bool = ($(this).attr("checked"))? true : false;
		$("[name=check_comment]").attr("checked",bool);
	});

	//보기전체 선택
	$("[name=all_view]").click(function(){
		var bool = ($(this).attr("checked"))? true : false;
		$("[name=check_view]").attr("checked",bool);
	});
	
	$("#demo")
		.delegate('a', 'click', function(e,data){
			if($(this).parent("li").attr("rel") == 'default'){
				location.replace(uri_template[$("[name=page_type]").val()]+"/id/"+$(this).parent("li").attr("id").replace('node_',''));
			}
		}) 
		.bind("before.jstree", function (e, data) {
			$("#alog").append(data.func + "<br />");
		})
		.jstree({ 
			"themes" : {
				"theme" : "classic",
				"dots" : false,
				"icons" : false
			},		
			// List of active plugins
			"plugins" : [ 
				"themes","json_data","ui","crrm","cookies","dnd","search","types","hotkeys","contextmenu" 
			],
	
			// I usually configure the plugin that handles the data first
			// This example uses JSON as it is most common
			"json_data" : { 
				// This tree is ajax enabled - as this is most common, and maybe a bit more complex
				// All the options are almost the same as jQuery's AJAX (read the docs)
				"ajax" : {
					// the URL to fetch the data
					"url" : "/chmanager/contents/ajax_menu",
					// the `data` function is executed in the instance's scope
					// the parameter is the node being loaded 
					// (may be -1, 0, or undefined when loading the root nodes)
					"data" : function (n) { 
						// the result is fed to the AJAX request `data` option
						return { 
							"operation" : "get_children", 
							"id" : n.attr ? n.attr("id").replace("node_","") : 1 
						}; 
					}
				}
			},
			// Configuring the search plugin
			"search" : {
				// As this has been a common question - async search
				// Same as above - the `ajax` config option is actually jQuery's AJAX object
				"ajax" : {
					"url" : "/chmanager/contents/ajax_menu",
					// You get the search string as a parameter
					"data" : function (str) {
						return { 
							"operation" : "search", 
							"search_str" : str 
						}; 
					}
				}
			},
			// Using types - most of the time this is an overkill
			// read the docs carefully to decide whether you need types
			"types" : {
				// I set both options to -2, as I do not need depth and children count checking
				// Those two checks may slow jstree a lot, so use only when needed
				"max_depth" : -2,
				"max_children" : -2,
				// I want only `drive` nodes to be root nodes 
				// This will prevent moving or creating any other type as a root node
				"valid_children" : [ "drive" ],
				"types" : {
					// The default type
					"default" : {
						// I want this type to have no children (so only leaf nodes)
						// In my case - those are files
						"valid_children" : "none",
						// If we specify an icon for the default type it WILL OVERRIDE the theme icons
						"icon" : {
							"image" : "/theme/<?=$_theme?>/common/theme/<?=$_theme?>/images/file.png"
						}
					},
					// The `folder` type
					"folder" : {
						// can have files and other folders inside of it, but NOT `drive` nodes
						"valid_children" : [ "default", "folder" ],
						"icon" : {
							"image" : "/theme/<?=$_theme?>/common/theme/<?=$_theme?>/images/folder.png"
						}
					},
					// The `drive` nodes 
					"drive" : {
						// can have files and folders inside, but NOT other `drive` nodes
						"valid_children" : [ "default", "folder" ],
						"icon" : {
							"image" : "/theme/<?=$_theme?>/common/theme/<?=$_theme?>/images/root.png"
						},
						// those prevent the functions with the same name to be used on `drive` nodes
						// internally the `before` event is used
						"start_drag" : false,
						"move_node" : false,
						"delete_node" : false,
						"remove" : false
					}
				}
			},
			// UI & core - the nodes to initially select and open will be overwritten by the cookie plugin
	
			// the UI plugin - it handles selecting/deselecting/hovering nodes
			"ui" : {
				// this makes the node with ID node_4 selected onload
				"initially_select" : [ "node_4" ]
			},
			// the core plugin - not many options here
			"core" : { 
				// just open those two nodes up
				// as this is an AJAX enabled tree, both will be downloaded from the server
				"initially_open" : [ "node_2" , "node_3" ] 
			}
		})
		.bind("create.jstree", function (e, data) {
			$.post(
				"/chmanager/contents/ajax_menu", 
				{ 
					"operation" : "create_node", 
					"id" : data.rslt.parent.attr("id").replace("node_",""), 
					"position" : data.rslt.position,
					"title" : data.rslt.name,
					"type" : data.rslt.obj.attr("rel")
				}, 
				function (r) {
					if(r.status) {
						$(data.rslt.obj).attr("id", "node_" + r.id);
					}
					else {
						$.jstree.rollback(data.rlbk);
					}
				}
			);
		})
		.bind("remove.jstree", function (e, data) {
			data.rslt.obj.each(function () {
				$.ajax({
					async : false,
					type: 'POST',
					url: "/chmanager/contents/ajax_menu",
					data : { 
						"operation" : "remove_node", 
						"id" : this.id.replace("node_","")
					}, 
					success : function (r) {
						if(!r.status) {
							data.inst.refresh();
						}
					}
				});
			});
		})
		.bind("rename.jstree", function (e, data) {
			$.post(
				"/chmanager/contents/ajax_menu", 
				{ 
					"operation" : "rename_node", 
					"id" : data.rslt.obj.attr("id").replace("node_",""),
					"title" : data.rslt.new_name
				}, 
				function (r) {
					if(!r.status) {
						$.jstree.rollback(data.rlbk);
					}
				}
			);
		})
		.bind("move_node.jstree", function (e, data) {
			data.rslt.o.each(function (i) {
				$.ajax({
					async : false,
					type: 'POST',
					url: "/chmanager/contents/ajax_menu",
					data : { 
						"operation" : "move_node", 
						"id" : $(this).attr("id").replace("node_",""), 
						"ref" : data.rslt.cr === -1 ? 1 : data.rslt.np.attr("id").replace("node_",""), 
						"position" : data.rslt.cp + i,
						"title" : data.rslt.name,
						"copy" : data.rslt.cy ? 1 : 0
					},
					success : function (r) {
						if(!r.status) {
							$.jstree.rollback(data.rlbk);
						}
						else {
							$(data.rslt.oc).attr("id", "node_" + r.id);
							if(data.rslt.cy && $(data.rslt.oc).children("UL").length) {
								data.inst.refresh(data.inst._get_parent(data.rslt.oc));
							}
						}
						$("#analyze").click();
					}
				});
			});
		});
	
		//버튼 설정	
		$("#mmenu input").click(function () {
			switch(this.id) {
				case "add_default":
				case "add_folder":
					$("#demo").jstree("create", null, "last", { "attr" : { "rel" : this.id.toString().replace("add_", "") } });
					break;
				case "search":
					$("#demo").jstree("search", document.getElementById("text").value);
					break;
				case "text": break;
				default:
					$("#demo").jstree(this.id);
					break;
			}
		});
});
//-->
</script>

